package pers.zc.activiti.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import pers.zc.activiti.aop.MuBiaoClassImpl;
import pers.zc.activiti.aop.MuBiaoClassImpl2;
import pers.zc.activiti.config.AsyncExecutorConfig;

/**
 * @Annotion:
 * @ClassName: TestThread
 * @Author: Lin Fuyuan
 * @Date: 2019/9/26  10:34
 * @Version: 1.0
 */
@Controller
@RequestMapping("/aop")
public class TestAopController {
    @Autowired
    private MuBiaoClassImpl muBiaoClass;
    @Autowired
    private MuBiaoClassImpl2 muBiaoClassImpl2;
    @Autowired
    private AsyncExecutorConfig asyncExecutorConfig;
   @GetMapping("test")
   public  void test() {
       for(int i = 0;i<4;i++){
           muBiaoClass.test(String.valueOf(i));
       }
       System.out.println("----------");
   }
   /**
    * 测试aop 的并发
    * @author Lin FuYuan
    * @param
    * @date 2020/1/14
    * @return void
    */
    @GetMapping("testThread")
   public void testBf(){
        ThreadPoolTaskExecutor asyncExecutor = (ThreadPoolTaskExecutor) asyncExecutorConfig.getAsyncExecutor();
        for (int i = 0; i<5;i++){
            int finalI = i;
            Runnable runnable = new Runnable(){
                @Override
                public void run() {
                    muBiaoClass.test("并发:"+ finalI);
                }

            };
            asyncExecutor.execute(runnable);
        }
        System.out.println("结束调用");

   }

}
